<template>
	<view>
		<scroll-view scroll-y="true" :style="{height: wh + 'px'}" @scrolltolower="scrollLower">
			<view  v-for="(item,index) in orders" :key="index">
				<navigator class="order-list" :url="'/subpkg/order-list-detail/order-list-detail?orderId='+item.id">
					<!-- 左边logo -->
					<view>
						<uni-icons customPrefix="order" type="icon-hsjcweixinzhifu" size="40" color="#09bb07"></uni-icons>
					</view>
					<!-- 右边信息 -->
					<view class="order-list-right">
						<view class="order-list-right-line">
							<view>预约成功</view>
							<view class="order-list-right-line-price">￥{{item.price}}.00</view>
						</view>
						<view class="order-list-right-line">
							<view style="color: gray; font-size: 12px;">{{names[index]}}</view>
							<view style="color: gray; font-size: 12px;">{{item.createTime}}</view>
						</view>
					</view>
				</navigator>
			</view>
			<uni-load-more :status="status"></uni-load-more>
		</scroll-view>
	</view>
</template>

<script>
	import {mapState} from 'vuex'
	export default {
		data() {
			return {
				wh:0,
				page:1,
				limit:8,
				totalPage:0,
				status:"more",
				orders:[],
				names:[]
			};
		},
		computed:{
			...mapState('m_user',['openid'])
		},
		onLoad() {
			const sysInfo = uni.getSystemInfoSync()
			this.wh = sysInfo.windowHeight
			console.log(this.wh)
			this.getOrderList()
		},
		methods:{
			scrollLower() {
				console.log('触发了')
			    if (this.page >= this.totalPage) {
			       this.status = "noMore"
			       return
			    } else {
			       this.status = "loading"
			    }
			    this.page++
			    this.timer = setTimeout(() => {
					this.getOrderList()
			    }, 200)
			    console.log('我滚动到底部了')
			},
			   
			getOrderList(page=1,limit){
				uni.request({
					url:'http://192.168.43.224:9002/order/getOrderList/'+this.page+'/'+this.limit+'/'+this.openid,
					method:'GET',
					success: (res) => {
						this.totalPage = res.data.data.pages
						console.log(this.totalPage)
						for(var i = 0; i < res.data.data.records.length; i++){
							this.orders.push(res.data.data.records[i])
							this.getNameById(res.data.data.records[i].userId)
						}
					},
					complete: (res) => {
						wx.hideLoading()
						wx.stopPullDownRefresh()
					}
				})
			},
			
			//获取用户姓名
			getNameById(id){
				uni.request({
					url:'http://192.168.43.224:9002/user/getNameById/'+id,
					method:'GET',
					success: (res) => {
						this.names.push(res.data.data)
						console.log(this.names)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
.order-list{
	margin-top: 10px;
	width: 100%;
	height: 75px;
	display: flex;
	background-color: #EBEEF5;
	box-shadow: 5rpx #C0C4CC;
	// justify-content: center;
	align-items: center;
	padding-left: 15px;
}
.order-list-right{
	height: 100%;
	width: 100%;
	margin: 5px 10px;
	.order-list-right-line{
		display: flex;
		justify-content: space-between;
		padding-left: 10px;
		padding-right: 20px;
		padding-top: 10px;
		.order-list-right-line-price{
			color: #F0AD4E;
		}
	}
}
</style>
